package com.chonry.web2.algorithm;

import io.shardingjdbc.core.api.algorithm.sharding.PreciseShardingValue;
import io.shardingjdbc.core.api.algorithm.sharding.standard.PreciseShardingAlgorithm;
import java.util.Collection;
import java.util.Iterator;

public class ShardingTableAlgorithm implements PreciseShardingAlgorithm<Integer> {
    public ShardingTableAlgorithm() {
    }

    public String doSharding(Collection<String> collection, PreciseShardingValue<Integer> preciseShardingValue) {
        int tableSize = collection.size();
        String tblSuffix = String.valueOf((Integer)preciseShardingValue.getValue() % (tableSize - 1) + 1);
        Iterator var5 = collection.iterator();

        String each;
        int lastIndex;
        do {
            if (!var5.hasNext()) {
                throw new UnsupportedOperationException();
            }

            each = (String)var5.next();
            if ((Integer)preciseShardingValue.getValue() == 0) {
                return each;
            }

            lastIndex = each.lastIndexOf("_");
        } while(!each.substring(lastIndex + 1).equals(tblSuffix));

        return each;
    }
}
